﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace WindowsFormsApplication1
{
    public partial class frmTKChatluongDaotao : Form
    {
        int i;
        SqlConnection connection = new SqlConnection("Data Source=.;Initial Catalog=SM;Integrated Security=True");
        public frmTKChatluongDaotao()
        {
            InitializeComponent();
            groupControl1.Enabled = false;
        }

        DataSet FillDataset(string sql)
        {
            DataSet ds = new DataSet();
            try
            {
                SqlDataAdapter adap = new SqlDataAdapter(sql, connection);
                adap.Fill(ds);
                adap.Dispose();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error " + ex.Message);
            }
            return ds;
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            bool ktra = dxValidationProvider1.Validate();
            if (ktra)
            {
                DataSet ds = FillDataset("select MasvID from Query2 where Namhoc = N'" + txtNamhoc.Text + "'");
                int count = ds.Tables[0].Rows.Count;
                if (count > 0)
                    groupControl1.Enabled = true;
                else
                    MessageBox.Show("Không có sinh viên nào", "Thông báo");
            }
            else
                MessageBox.Show("Bạn chưa nhập dữ liệu cần thiết", "Quản lý sinh viên", MessageBoxButtons.OK, MessageBoxIcon.None);
       
        }

        private void rdgThongke_SelectedIndexChanged(object sender, EventArgs e)
        {
            int selectedIndex = rdgThongke.SelectedIndex;
            if (selectedIndex == 0)
                i = 0;  //Thống kê chất lượng sinh viên theo ngành
            else if (selectedIndex == 1)
                i = 1; //Thống kê chất lượng sv theo khóa
            else if (selectedIndex == 2)
                i = 2; //Thông kê chất lượng sv theo lớp
            else
                i = 3; //thống kê chất lượng sv theo phái
        }

        private void btnXem_Click(object sender, EventArgs e)
        {
            if (i == 0)
            {
                rptTKChatLuongSVTheoNganh rpt = new rptTKChatLuongSVTheoNganh();
                DataSet ds = FillDataset("exec PC_TKChatLuongSVTheoNganh '" + txtNamhoc.Text + "'");
                rpt.DataSource = ds;
                rpt.BindData(txtNamhoc.Text);
                rpt.PrintingSystem.PreviewFormEx.MdiParent = RibbonForm1.ActiveForm;
                rpt.ShowPreview();
            }
            else if (i == 1)
            {
                rptTKChatLuongSVTheoKhoa rpt = new rptTKChatLuongSVTheoKhoa();
                DataSet ds = FillDataset("exec PC_TKChatLuongSVTheoKhoa '" + txtNamhoc.Text + "'");
                rpt.DataSource = ds;
                rpt.BindData(txtNamhoc.Text);
                rpt.PrintingSystem.PreviewFormEx.MdiParent = RibbonForm1.ActiveForm;
                rpt.ShowPreview();
            }
            else if (i == 2)
            {
                rptTKChatLuongSVTheoLop rpt = new rptTKChatLuongSVTheoLop();
                DataSet ds = FillDataset("exec PC_TKChatLuongSVTheoLop '" + txtNamhoc.Text + "'");
                rpt.DataSource = ds;
                rpt.BindData(txtNamhoc.Text);
                rpt.PrintingSystem.PreviewFormEx.MdiParent = RibbonForm1.ActiveForm;
                rpt.ShowPreview();
            }
            else
            {
                rptTKChatLuongSVTheoPhai rpt = new rptTKChatLuongSVTheoPhai();
                DataSet ds = FillDataset("exec PC_TKChatLuongSVTheoPhai '" + txtNamhoc.Text + "'");
                rpt.DataSource = ds;
                rpt.BindData(txtNamhoc.Text);
                rpt.PrintingSystem.PreviewFormEx.MdiParent = RibbonForm1.ActiveForm;
                rpt.ShowPreview();
            }

        }

        private void btnThoat_Click(object sender, EventArgs e)
        {
            this.Close();
        }

      
    }
}
